home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games Extra 1996 September / Amiga Games Extra CD-ROM 9-1996.iso / userbox / publicdomain / vim-4.2 / src / gui.h < prev    next >
C/C++ Source or Header  |  1996-06-09  |  8KB  |  233 lines

  1. /* vi:set ts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved            by Bram Moolenaar
  4.  *                                Motif support by Robert Webb
  5.  *
  6.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  7.  * Do ":help credits" in Vim to see a list of people who contributed.
  8.  */
  9.  
  10. /* For debugging */
  11. /* #define D(x)    printf x; */
  12. #define D(x)
  13.  
  14. #ifdef USE_GUI_MOTIF
  15. # define USE_GUI_X11
  16. # include <Xm/Xm.h>
  17. #endif
  18.  
  19. /*
  20.  * No, Athena doesn't work.  Probably never will, there is probably a public
  21.  * domain X widget set that is more like Motif which should be used instead.
  22.  */
  23. #ifdef USE_GUI_ATHENA
  24. # define USE_GUI_X11
  25. # include <X11/Intrinsic.h>
  26. # include <X11/StringDefs.h>
  27. #endif
  28.  
  29. /*
  30.  * These macros convert between character row/column and pixel coordinates.
  31.  * TEXT_X    - Convert character column into X pixel coord for drawing strings.
  32.  * TEXT_Y    - Convert character row into Y pixel coord for drawing strings.
  33.  * FILL_X    - Convert character column into X pixel coord for filling the area
  34.  *                under the character.
  35.  * FILL_Y    - Convert character row into Y pixel coord for filling the area
  36.  *                under the character.
  37.  * X_2_COL    - Convert X pixel coord into character column.
  38.  * Y_2_ROW    - Convert Y pixel coord into character row.
  39.  */
  40. #define TEXT_X(col)        ((col) * gui.char_width  + gui.border_offset)
  41. #define TEXT_Y(row)        ((row) * gui.char_height + gui.char_ascent \
  42.                                                  + gui.border_offset)
  43. #define FILL_X(col)        ((col) * gui.char_width  + gui.border_offset)
  44. #define FILL_Y(row)        ((row) * gui.char_height + gui.border_offset)
  45. #define X_2_COL(x)        (((x) - gui.border_offset) / gui.char_width)
  46. #define Y_2_ROW(y)        (((y) - gui.border_offset) / gui.char_height)
  47.  
  48. /* Menu modes */
  49. #define MENU_NORMAL_MODE    0x01
  50. #define MENU_VISUAL_MODE    0x02
  51. #define MENU_INSERT_MODE    0x04
  52. #define MENU_CMDLINE_MODE    0x08
  53. #define MENU_ALL_MODES        0x0f
  54.  
  55. /* Indices into GuiMenu->strings[] and GuiMenu->noremap[] for each mode */
  56. #define MENU_INDEX_INVALID    -1
  57. #define MENU_INDEX_NORMAL    0
  58. #define MENU_INDEX_VISUAL    1
  59. #define MENU_INDEX_INSERT    2
  60. #define MENU_INDEX_CMDLINE    3
  61.  
  62. /* Update types for scrollbars, getting more severe on the way down */
  63. #define SB_UPDATE_NOTHING    0
  64. #define SB_UPDATE_VALUE        1
  65. #define SB_UPDATE_HEIGHT    2
  66. #define SB_UPDATE_CREATE    3
  67.  
  68. /* Indices for arrays of scrollbars */
  69. #define SB_NONE                -1
  70. #define SB_LEFT                0
  71. #define SB_RIGHT            1
  72. #define SB_BOTTOM            2
  73.  
  74. /* Default size of scrollbar */
  75. #define SB_DEFAULT_WIDTH    20
  76.  
  77. /* Default height of the menu bar */
  78. #define MENU_DEFAULT_HEIGHT 32
  79.  
  80. /* Highlighting attribute bits. */
  81. #define HL_NORMAL                0x00
  82. #define HL_INVERSE                0x01
  83. #define HL_BOLD                    0x02
  84. #define HL_ITAL                    0x04
  85. #define HL_UNDERLINE            0x08
  86. #define HL_STANDOUT                0x10
  87. #define HL_SELECTED                0x20
  88. #define HL_ALL                    0x3f
  89.  
  90. #ifdef USE_GUI_X11
  91.  
  92. /* Selection states for X11 selection. */
  93. #define SELECT_CLEARED            0
  94. #define SELECT_IN_PROGRESS        1
  95. #define SELECT_DONE                2
  96.  
  97. #define SELECT_MODE_CHAR        0
  98. #define SELECT_MODE_WORD        1
  99. #define SELECT_MODE_LINE        2
  100.  
  101. #endif
  102.  
  103. /*
  104.  * When we know the cursor is no longer being displayed (eg it has been written
  105.  * over).
  106.  */
  107. #define INVALIDATE_CURSOR()        (gui.cursor_row = -1)
  108.  
  109. /* #define INVALIDATE_CURSOR()    do{printf("Invalidate cursor %d\n", __LINE__); gui.cursor_row = -1;}while(0) */
  110.  
  111. /*
  112.  * For checking whether cursor needs redrawing, or whether it doesn't need
  113.  * undrawing.
  114.  */
  115. #define IS_CURSOR_VALID()        (gui.cursor_row >= 0)
  116.  
  117. typedef struct GuiSelection
  118. {
  119.     int            owned;                /* Flag: do we own the selection? */
  120.     FPOS        start;                /* Start of selected area */
  121.     FPOS        end;                /* End of selected area */
  122. #ifdef USE_GUI_X11
  123.     Atom        atom;                /* Vim's own special selection format */
  124.     short_u        origin_row;
  125.     short_u        origin_start_col;
  126.     short_u        origin_end_col;
  127.     short_u        word_start_col;
  128.     short_u        word_end_col;
  129.     FPOS        prev;                /* Previous position */
  130.     short_u        state;                /* Current selection state */
  131.     short_u        mode;                /* Select by char, word, or line. */
  132. #endif
  133. } GuiSelection;
  134.  
  135. typedef struct GuiMenu
  136. {
  137.     int            modes;                /* Which modes is this menu visible for? */
  138.     char_u        *name;                /* Name shown in menu */
  139.     void        (*cb)();            /* Call-back routine */
  140.     char_u        *strings[4];        /* Mapped string for each mode */
  141.     int            noremap[4];            /* A noremap flag for each mode */
  142.     struct GuiMenu *children;        /* Children of sub-menu */
  143.     struct GuiMenu *next;            /* Next item in menu */
  144. #ifdef USE_GUI_X11
  145.     Widget        id;                    /* Manage this to enable item */
  146.     Widget        submenu_id;            /* If this is submenu, add children here */
  147. #endif
  148. } GuiMenu;
  149.  
  150. typedef struct GuiScrollbar
  151. {
  152.     int            update[2];            /* What kind of update is required? */
  153.                                     /* (For left & right scrollbars) */
  154.     int            value;                /* Represents top line number visible */
  155.     int            size;                /* Size of scrollbar thumb */
  156.     int            max;                /* Number of lines in buffer */
  157.     int            top;                /* Top of scroll bar (chars from row 0) */
  158.     int            height;                /* Height of scroll bar (num rows) */
  159.     int            status_height;        /* Height of status line */
  160. #ifdef USE_GUI_X11
  161.     Widget        id[2];                /* Id of real scroll bar (left & right) */
  162. #endif
  163. } GuiScrollbar;
  164.  
  165. typedef struct Gui
  166. {
  167.     int            in_focus;            /* Vim has input focus */
  168.     int            in_use;                /* Is the GUI being used? */
  169.     int            starting;            /* GUI will start in a little while */
  170.     int            dying;                /* Is vim dying? Then output to terminal */
  171.     int            dofork;                /* Use fork() when GUI is starting */
  172.     int            dragged_sb;            /* Which scrollbar being dragged, if any? */
  173.     struct window    *dragged_wp;    /* Which WIN's sb being dragged, if any? */
  174.     int            col;                /* Current cursor column in GUI display */
  175.     int            row;                /* Current cursor row in GUI display */
  176.     int            cursor_col;            /* Physical cursor column in GUI display */
  177.     int            cursor_row;            /* Physical cursor row in GUI display */
  178.     int            num_cols;            /* Number of columns */
  179.     int            num_rows;            /* Number of rows */
  180.     int            scroll_region_top;    /* Top (first) line of scroll region */
  181.     int            scroll_region_bot;    /* Bottom (last) line of scroll region */
  182.     long_u        highlight_mask;        /* Highlight attribute mask */
  183.     GuiSelection selection;            /* Info about selected text */
  184.     GuiMenu        *root_menu;            /* Root of menu hierarchy */
  185.     int            num_scrollbars;        /* Number of scrollbars (= #windows + 1) */
  186.     int            scrollbar_width;    /* Width of scrollbars */
  187.     int            menu_height;        /* Height of the menu bar */
  188.     int            menu_is_active;        /* TRUE if menu is present */
  189.     GuiScrollbar cmdline_sb;        /* Scroll bar for command line */
  190.                                     /* (Other scrollbars in 'struct window') */
  191.     int            which_scrollbars[3];/* Which scrollbar boxes are active? */
  192.     int            new_sb[3];            /* Which scrollbar boxes are new? */
  193.     int            prev_wrap;            /* For updating the horizontal scrollbar */
  194.     int            char_width;            /* Width of char in pixels */
  195.     int            char_height;        /* Height of char in pixels */
  196.     int            char_ascent;        /* Ascent of char in pixels */
  197.     int            border_width;        /* Width of our border around text area */
  198.     int            border_offset;        /* Total pixel offset for all borders */
  199. #ifdef USE_GUI_X11
  200.     Display        *dpy;                /* X display */
  201.     Window        wid;                /* Window id of text area */
  202.     int            visibility;            /* Is window partially/fully obscured? */
  203.     GC            text_gc;
  204.     GC            back_gc;
  205.     GC            invert_gc;
  206.     XFontStruct    *norm_font;
  207.     XFontStruct    *bold_font;
  208.     XFontStruct    *ital_font;
  209.     XFontStruct    *boldital_font;
  210.     Pixel        back_pixel;            /* Pixel value of background */
  211.     Pixel        norm_pixel;            /* Pixel value of normal text */
  212.     Pixel        bold_pixel;            /* Pixel value of bold text */
  213.     Pixel        ital_pixel;            /* Pixel value of ital text */
  214.     Pixel        underline_pixel;    /* Pixel value of underlined text */
  215.     Pixel        cursor_pixel;        /* Pixel value of cursor */
  216.     Pixel        menu_fg_pixel;        /* Pixel value of menu foregound */
  217.     Pixel        menu_bg_pixel;        /* Pixel value of menu backgound */
  218.     Pixel        scroll_fg_pixel;    /* Pixel value of scrollbar foreground */
  219.     Pixel        scroll_bg_pixel;    /* Pixel value of scrollbar background */
  220.  
  221.     /* X Resources */
  222.     char_u        *dflt_font;            /* Resource font, used if 'font' not set */
  223.     char_u        *dflt_bold_fn;        /* Resource bold font */
  224.     char_u        *dflt_ital_fn;        /* Resource italic font */
  225.     char_u        *dflt_boldital_fn;    /* Resource bold-italic font */
  226.     char_u        *geom;                /* Geometry, eg "80x24" */
  227.     Bool        rev_video;            /* Use reverse video? */
  228. #endif
  229. } Gui;
  230.  
  231. extern Gui gui;                        /* this is in gui.c */
  232. extern int force_menu_update;        /* this is in gui.c */
  233.